package com.aishua.aishuawallet.diydialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aishua.aishuawallet.R;


/**
 * Created by aishua on 2017/2/17.
 */

public class ExitLoginDialog extends DialogFragment {

    private View.OnClickListener sure_listener;
    private View.OnClickListener cancle_listener;


    public void setSureButtonListener(View.OnClickListener listener) {
        sure_listener = listener;
    }

    public void setCancleButtonListener(View.OnClickListener listener) {

        this.cancle_listener = listener;
    }

    public static ExitLoginDialog newInstance(String msg) {

        ExitLoginDialog dialog = new ExitLoginDialog();
        Bundle args = new Bundle();
        args.putString("msg", msg);
        dialog.setArguments(args);
        return dialog;
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        String msg = getArguments().getString("msg");


        LayoutInflater inflaterDl = LayoutInflater.from(getActivity());
        LinearLayout layout = (LinearLayout) inflaterDl.inflate(R.layout.exit_dialog, null);

        //对话框
        final Dialog dialog = new Dialog(getActivity(),R.style.common_dialog_style);
        dialog.setContentView(layout);
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        dialogWindow.setGravity(Gravity.CENTER);
        lp.width = (int) getResources().getDimension(R.dimen.dialog_exit_width); ; // 宽度

        lp.height = LinearLayout.LayoutParams.WRAP_CONTENT; // 高度
        // 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
        // dialog.onWindowAttributesChanged(lp);
        dialogWindow.setAttributes(lp);

        Button exit_cancel =  layout.findViewById(R.id.exit_cancel);
        Button exit_sure = layout.findViewById(R.id.exit_sure);

        TextView tv_down_result =  layout.findViewById(R.id.tv_exit_tips);
        tv_down_result.setText(msg);
        if (sure_listener !=null){

            exit_sure.setOnClickListener(sure_listener);
        }
       if (cancle_listener != null){

           exit_cancel.setOnClickListener(cancle_listener);
       }

        return dialog;

    }

}
